﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ChucNang_Admin_Admin_ThemDoiTacCon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnTroVe_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ChucNang/Admin/Admin_XemDanhSachPhanLoai.aspx");

    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        int? kq=0;
        int Id_Cha=int.Parse(Request.QueryString["Id_Cha"]);
        DataDSTableAdapters.PHANLOAITableAdapter pladapter = new DataDSTableAdapters.PHANLOAITableAdapter();
        string imageFolder = ConfigurationSettings.AppSettings["IMAGE_FOLDER"];
        pladapter.PHANLOAI_ThemPhanLoai(txtTenPhanLoai.Text, Id_Cha,imageFolder + fileuploadHinhAnh.FileName, ref kq);
        string strFilename;

        if (fileuploadHinhAnh.FileName != "")
        {
            strFilename = Server.MapPath(imageFolder + fileuploadHinhAnh.FileName);
            fileuploadHinhAnh.PostedFile.SaveAs(strFilename);
        }

        int soluongthuoctinh = int.Parse(txtSoLuongThuocTinh.Value);
        DataDSTableAdapters.PHANLOAI_THUOCTINHTableAdapter plttAdapter = new DataDSTableAdapters.PHANLOAI_THUOCTINHTableAdapter();
        for (int i = 0; i < soluongthuoctinh; i++ )
        {
            int idThuocTinh = int.Parse(Request.Form.Get("select_"+i));
            plttAdapter.PHANLOAI_THUOCTINH_Them(kq, idThuocTinh);
        }


        if (kq > 0)
            Response.Write("<script>alert('Thêm loại sản phẩm thành công');location.href='Admin_XemDanhSachPhanLoai.aspx';</script>");
        else
            Response.Write("<script>alert('Thêm loại sản phẩm không thành công');location.href='Admin_XemDanhSachPhanLoai.aspx';</script>");
    }
}
